<!DOCTYPE html>
<html>
  <head>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/resources/get-host-info.js"></script>
  </head>
  <body>
  <script>
    async_test(function () {
      window.addEventListener("message", this.step_func(function (event) {
        if (event.data.test == "send-fetch-referrer") {
          assert_equals(document.location.origin + "/", event.data.referrer);
          this.done();
        } else if (event.data.test == "dynamic-referrer-policy") {
          var meta = document.createElement("meta");
          meta.name = "referrer";
          meta.content = "origin";
          document.head.appendChild(meta);
          event.source.postMessage({
            command: "send-fetch-referrer",
            url: get_host_info().UNAUTHENTICATED_ORIGIN + "/security/resources/echo-referrer-header.php",
          }, "*");
        } else {
          assert_unreached("Unexpected message: " + event.data.test);
          this.done();
        }
      }));
    }, "srcdoc iframe uses parent's referrer policy, set after iframe was created");
  </script>
  <iframe srcdoc="<script src='resources/referrer-policy-srcdoc.php?test=dynamic-referrer-policy'></script>"></iframe>
  </body>
</html>
